import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig(({command, mode})=>{
  const env = loadEnv(mode, process.cwd(), '')
  // console.log(env);
  const viteConfig = {
    resolve: {
      alias: {
        '@ide': path.resolve(__dirname, './src/ide'),
        '@': path.resolve(__dirname, './src')
      }
    },
    plugins: [react()],
    server: {
      host: '0.0.0.0',
      port: 5174
    }
  }

  if(env.VITE_EVN==='development'){
    viteConfig.plugins.push({
      name: 'html-transform',
      transformIndexHtml(html){
        return html.replace('/versionConfig.js','/versionConfig-demo.js')
      }
    })
  }

  return viteConfig;
});
